home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 44 / PC Actual CD 44.iso / Linux / Cygwin / full.exe / Disk1 / data1.cab / Tools / share / tix4.1 / demos / samples / SGrid0.tcl < prev    next >
Encoding:
Text File  |  1998-12-04  |  3.2 KB  |  132 lines

  1. # Tix Demostration Program
  2. #
  3. # This sample program is structured in such a way so that it can be
  4. # executed from the Tix demo program "widget": it must have a
  5. # procedure called "RunSample". It should also have the "if" statment
  6. # at the end of this file so that it can be run as a standalone
  7. # program using tixwish.
  8.  
  9. # A very simple demonstration of the tixGrid widget
  10. #
  11.  
  12. proc RunSample {w} {
  13.     wm title $w "The First Grid Example"
  14.     wm geometry $w 480x300
  15.  
  16.     set top [frame $w.f -bd 1 -relief raised]
  17.     set box [tixButtonBox $w.b -bd 1 -relief raised]
  18.  
  19.     pack $box -side bottom -fill both
  20.     pack $top -side top -fill both -expand yes
  21.  
  22.     label $top.lab -text "This widget is still under alpha
  23. Please ignore the debug messages
  24. Not all features have been implemented" -justify left
  25.     pack $top.lab -side top -anchor c -padx 3 -pady 3
  26.  
  27.     MakeGrid $top
  28.  
  29.     # Create the buttons
  30.     #
  31.     $box add ok     -text Ok     -command "destroy $w" -width 6
  32.     $box add cancel -text Cancel -command "destroy $w" -width 6
  33. }
  34.  
  35. # This command is called whenever the background of the grid needs to
  36. # be reformatted. The x1, y1, x2, y2 specifies the four corners of the area
  37. # that needs to be reformatted.
  38. #
  39. # area:
  40. #  x-margin:    the horizontal margin
  41. #  y-margin:    the vertical margin
  42. #  s-margin:    the overlap area of the x- and y-margins
  43. #  main:    The rest
  44. #
  45. proc SimpleFormat {w area x1 y1 x2 y2} {
  46.  
  47.     global margin
  48.     set bg(s-margin) gray65
  49.     set bg(x-margin) gray65
  50.     set bg(y-margin) gray65
  51.     set bg(main)     gray20
  52.  
  53.     case $area {
  54.     main {
  55.         # The "grid" format is consecutive boxes without 3d borders
  56.         #
  57.         $w format grid $x1 $y1 $x2 $y2 \
  58.         -relief raised -bd 1 -bordercolor $bg($area) -filled 0 -bg red\
  59.         -xon 1 -yon 1 -xoff 0 -yoff 0 -anchor se
  60.     }
  61.     {x-margin y-margin s-margin} {
  62.         # border specifies consecutive 3d borders
  63.         #
  64.         $w format border $x1 $y1 $x2 $y2 \
  65.         -fill 1 -relief raised -bd 1 -bg $bg($area) \
  66.         -selectbackground gray80
  67.     }
  68.     }
  69. }
  70.  
  71. # Print a number in $ format
  72. #
  73. #
  74. proc Dollar {s} {
  75.     set n [string len $s]
  76.     set start [expr $n % 3]
  77.     if {$start == 0} {
  78.     set start 3
  79.     }
  80.  
  81.     set str ""
  82.     for {set i 0} {$i < $n} {incr i} {
  83.     if {$start == 0} {
  84.         append str ","
  85.         set start 3
  86.     }
  87.     incr start -1
  88.     append str [string index $s $i]
  89.     }
  90.     return $str
  91. }
  92.  
  93. proc MakeGrid {w} {
  94.     # Create the grid
  95.     #
  96.     tixScrolledGrid $w.g -bd 0
  97.     pack $w.g -expand yes -fill both -padx 3 -pady 3
  98.  
  99.     set grid [$w.g subwidget grid]
  100.     $grid config -formatcmd "SimpleFormat $grid"
  101.  
  102.  
  103.     # Set the size of the columns
  104.     #
  105.     $grid size col 0 -size 10char
  106.     $grid size col 1 -size auto
  107.     $grid size col 2 -size auto
  108.     $grid size col 3 -size auto
  109.     $grid size col 4 -size auto
  110.  
  111.     # set the default size of the column and rows. these sizes will be used
  112.     # if the size of a row or column has not be set via the "size col ?"
  113.     # command
  114.     $grid size col default -size 5char
  115.     $grid size row default -size 1.1char -pad0 3
  116.  
  117.     for {set x 0} {$x < 10} {incr x} {
  118.     for {set y 0} {$y < 10} {incr y} {
  119.         $grid set $x $y -itemtype text -text ($x,$y)
  120.     }
  121.     }
  122. }
  123.  
  124.  
  125. if {![info exists tix_demo_running]} {
  126.     wm withdraw .
  127.     set w .demo
  128.     toplevel $w
  129.     RunSample $w
  130.     bind $w <Destroy> exit
  131. }
  132.